package demo;

import demo.filter.CrossFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;


@EnableZuulProxy		//路由代理
@EnableDiscoveryClient //添加发现服务的能力
@SpringBootApplication
@EnableHystrix          //@EnableHystrix  开启断路器
@EnableCircuitBreaker
@Configuration
@EnableAutoConfiguration
public class HmblRibbonApplication {

	@Bean
	@LoadBalanced //开启负载均衡
    RestTemplate restTemplate() {
		return new RestTemplate();
	}

	public static void main(String[] args) {
		SpringApplication.run(HmblRibbonApplication.class, args);
	}



	@Bean
	public FilterRegistrationBean crossServlet() {
		FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
		filterRegistrationBean.setFilter(new CrossFilter());
		filterRegistrationBean.addUrlPatterns("");
		return filterRegistrationBean;
	}

}
